<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>登录-二手市场</title>
		<link type="text/css" id="layuicss-laydatecss" rel="stylesheet"
			href="css/lib/layui/css/modules/laydate/laydate.css">
		<link type="text/css" id="layuicss-skinlayercss" rel="stylesheet"
			href="css/lib/layui/css/modules/layer/default/layer.css">
		<link type="text/css" id="layuicss-skincodecss" rel="stylesheet"
			href="css/lib/layui/css/modules/code.css">
		<link type="text/css" rel="stylesheet" href="css/layui.css">
		<link type="text/css" rel="stylesheet" href="css/public.css">
		<link type="text/css" rel="stylesheet" href="css/login.css">
	</head>
	<body>
	    <div id="app">
			<div id="header">
				<%--<a href="" class="logo"></a>--%>
			</div>
			<div id="login-main">
				<div class="layui-tab layui-tab-brief reg-left fl">
					<div class="layui-tab-content">
						<form class="layui-tab-item layui-show layui-form">
							<div class="layui-form-item">
								<input type="text" name="phone" autocomplete="off" lay-verify="phone"
									   placeholder="请输入手机号/邮箱" class="layui-input phoneNum" v-model="phone" @blur="check_phone()">
							</div>
							<div class="layui-form-item">
								<input type="password" name="password" autocomplete="off" lay-verify="password"
									   placeholder="请输入密码" class="layui-input password" v-model="password" @blur="check_password()">
							</div>
							<div class="layui-form-item forgetpwd">
								<a href="/user/forget_password">忘记密码？</a>
							</div>
							<a class="layui-btn login-btn" @click="check_login()">登 录</a>
						</form>
						<!-- <div class="layui-tab-item">内容2</div> -->
					</div>
				</div>
				<div class="log-right right-box fr">
					<p>没有账号？</p>
					<a href="/toregister_user">立即注册</a>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="js/common/axios.js"></script>
		<script type="text/javascript" src="js/common/vue.min.js"></script>
		<script type="text/javascript" src="js/common/vue-router.js"></script>
		<script type="text/javascript">
			let a = new Vue({
				el: "#app",
				data: {
					phone: '',
					password: ''
				},
				methods: {
					check_phone(){
						const _this = this;
						var phoneReg = /^1[3|4|5|7|8|9][0-9]\d{8}$/;
						if (_this.phone==''||_this.phone==undefined) {
							alert("请输入手机号");
							return false;
						} else if (!phoneReg.test(_this.phone)) {
							alert("手机号格式有误");
							return false;
						}
						return true;
					},
					check_password(){
						const _this = this;
						if (_this.password == '' || _this.password == undefined) {
							alert("请输入密码");
							return false;
						}
						return true;
					},
					check_login() {
						const _this = this;
						if(!(_this.check_phone()&&_this.check_password())){
							return ;
						}
						var params = new URLSearchParams();
						params.append('password', _this.password);
						params.append('phone', _this.phone);
						axios.post("/user/login", params).then(res=> {
							res = res.data;
							if (res.code == 1) {
								alert("登陆成功");
							} else {
								alert(res.msg);
							}
						}).catch(function(error) {
							console.info(error);
						})
						return true;
					}
				},
			})
		</script>
	</body>
</html>
